package cc.cix.gt.org.controller;

import cc.cix.gt.common.constant.StringConstant;
import cc.cix.gt.common.entity.ResultPage;
import cc.cix.gt.org.dto.query.QueryLogReq;
import cc.cix.gt.org.entity.Log;
import cc.cix.gt.org.service.ILogService;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author cix
 */
@Api(tags = "用户操作日志管理")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/log")
public class LogController {

    private final ILogService logService;

    @ApiOperation("用户操作日志列表")
    @GetMapping
    public ResultPage<Log> listLog(QueryLogReq dto) {
        return logService.listLog(dto);
    }

    @ApiOperation("删除用户操作日志")
    @PreAuthorize("hasAuthority('log:delete')")
    @DeleteMapping("/{ids}")
    public void deleteLogs(@PathVariable String ids) {
        logService.deleteLogByIds(StrUtil.splitTrim(ids, StringConstant.COMMA));
    }

}
